package client_tree;

import javax.swing.tree.DefaultMutableTreeNode;

import utils.Constants;

/**
 * Klasa koja predstavlja User cvor stabla korisnika. User objekat je osnovni objekat
 * modela podataka za JTree objekat. Na ovaj nacin se postize to, da nije potrebno
 * cuvati Usere (podatke) u dodatnim kolekcijama, vec se svi podaci cuvaju u modelu
 * podataka samog JTree objekta, koji je ujedno i View deo MVC obrasca stabla.<br>
 * Za svaki User objekat (cvor), setuje se da je on sam semi userObject (videti u
 * konstuktoru setUserObject(this)), sto znaci da User objekat pored funkcije osnovnog
 * cvora stabla, sadrzi i sve podatke koje karakterisu jednog usera (ovde kontakt) u
 * messenger-u. Na ovaj nacin se moze lako pristupiti zeljenim podacima preko cvora
 * stabla, za setovanje dodatnih karakteristika, npr. u TreeNodeCellRenderer objektu.
 * 
 * @author UrosKrkic & Radivoje Popovic
 */
public class User extends DefaultMutableTreeNode implements Constants {
	
	private String username;
	private String nickname;
	private String email;
	private String ip_address;
	private String localAddress;
	private int port;
	private int status;
	private String regDate;
	private String avatar;

	

	/**
	 * Konstruktor.
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public User(String username, String nickname, String email, String ip_address, String localAddress, int port, String status, String regDate, String avatar) {
		this.username = username;
		this.nickname = nickname;
		this.email = email;
		this.ip_address = ip_address;
		this.localAddress = localAddress;
		this.port = port;
		
		for (int i = 0; i < STATUS_NAMES.length; i++) {
			if (STATUS_NAMES[i].equals(status)) {
				this.status = i;
				break;
			}
		}
		
		this.regDate = regDate;
		this.avatar = avatar;

		
		// obezbedjuje da cvor sadrzi sve potrebne podatke
		this.setUserObject(this);
		
		/*
		 * Posto je User objekat cvor list, sprecava se da ovakav cvor ima naslednike (decu).
		 * Inace, u aplikaciji se i ne dodaju deca u ove cvorove, tako da zabrana dodavanja
		 * dece u User cvorove, odrazava doslednost da su oni listovi stabla.
		 */
		this.setAllowsChildren(false);
	}
	
	
	/**
	 * Omogucava ispis imena cvora u stablu.
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public String toString() {
		return nickname;
	}


	
	// getters & setters methods

	public String getAvatar() {
		return avatar;
	}



	public String getEmail() {
		return email;
	}



	public String getIp_address() {
		return ip_address;
	}



	public String getNickname() {
		return nickname;
	}



	public int getPort() {
		return port;
	}



	public int getStatus() {
		return status;
	}



	public String getUsername() {
		return username;
	}



	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}



	public void setEmail(String email) {
		this.email = email;
	}



	public void setNickname(String nickname) {
		this.nickname = nickname;
	}



	public void setStatus(int status) {
		this.status = status;
	}


	public String getRegDate() {
		return regDate;
	}


	public void setRegDate(String regDate) {
		this.regDate = regDate;
	}


	public void setIp_address(String ip_address) {
		this.ip_address = ip_address;
	}


	public void setPort(int port) {
		this.port = port;
	}


	public String getLocalAddress() {
		return localAddress;
	}


	public void setLocalAddress(String localAddress) {
		this.localAddress = localAddress;
	}
	
}
